import { FC } from "react";
import { View, Text } from "@tarojs/components";
import Taro from "@tarojs/taro";
import styles from "./index.module.less";
import { HIcon } from "@/components";
import { AtButton } from "taro-ui";
import request from "@/utils/request";

const Setting: FC = () => {
  const onProtocol = () => {
    Taro.navigateTo({
      url: "/package/member/protocol/index",
    });
  };

  const onAbout = () => {
    Taro.navigateTo({
      url: "/package/member/about-us/index",
    });
  };

  const onLoginOut = () => {
    Taro.showModal({
      content: "您确定要退出登陆吗",
      confirmColor: "#FD486E",
      success: (e) => {
        if (e.confirm) {
          request.removeToken();
          Taro.reLaunch({
            url: "/pages/login/index",
          });
        }
      },
    });
  };

  return (
    <View className={styles["setting-wrapper"]}>
      <View className={styles["label"]} onClick={onProtocol}>
        <Text>服务协议与隐私条款</Text>
        <HIcon type="youjiantou1" color="#999" />
      </View>
      <View className={styles["label"]} onClick={onAbout}>
        <Text>关于我们</Text>
        <HIcon type="youjiantou1" color="#999" />
      </View>
      <AtButton className={styles["btn"]} onClick={onLoginOut}>
        退出登录
      </AtButton>
    </View>
  );
};

export default Setting;
